﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;
using Db4objects.Db4o;
using Domain; 

namespace DAO
{
    public static class IncrementalDAO
    {
        public static long Incrementar(enum_Tipo_Incremental tipo)
        {
            using (IObjectContainer db = Connect.getDataBase())
            {
                try
                {
                    Incremental i = new Incremental();
                    i.Tipo = tipo;

                    IObjectSet inc = db.QueryByExample(i);

                    if (!inc.HasNext())
                        i.Id = 0;
                    else
                        i = (Incremental)inc.Next();

                    i.Id++;

                    db.Store(i);
                    db.Commit();

                    return i.Id--;
                }
                finally
                {
                    db.Close();
                }
            }
        }
    }
}
